layui.use(['jquery','layer','table','form','laydate'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    var table=layui.table;
    var form=layui.form;

    //刷新
    refresh=function refresh(){
        location.reload();
    }
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });

    //模糊查询
    search=function search(){
        var userCode=$("input[name=userCode]").val();
        var reason=$("input[name=reason]").val();
        var days=$("#days option:selected").text();
        var type;
        if($("#type option:selected").text()=="前端"){
            type=$("#type option:selected").val();
        }else if($("#type option:selected").text()=="后端"){
            type=$("#type option:selected").val();
        }
        getTable(userCode,reason,days,type);
    }

    //高级检索
    retrieval=function retrieval(){
        layer.open({
            type : 2,
            title : "高级检索",
            area : [ '900px', '480px' ],
            shade : 0,
            offset: 'auto',
            content :"advanced-retrieval.html",
            btn:['确定','取消'],
            yes: function(index, layero){
                var child = layero.find('iframe').contents();
                var userCode= child.find("input[name=userCode]").val();
                var reason=child.find("input[name=reason]").val();
                var type;
                if(child.find("#type option:selected").text()=="前端"){
                    type=child.find("#type option:selected").val();
                }else if(child.find("#type option:selected").text()=="后端"){
                    type=child.find("#type option:selected").val();
                }
                var endDate=child.find("input[name=endDate]").val();
                var param = {
                    'userCode':userCode,
                    'reason':reason,
                    'type':type,
                    'endDate':endDate,
                }
                $.ajax({
                    url:"/closure/getUnsealAdvancedRetrieval",
                    data:param,
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        demoTable(data.data);
                        layer.close(layer.index);
                    }
                })
            }
        })
    }

    getTable('','','','');

    function getTable(userCode,reason,days,type){
        var param={
            'userCode':userCode,
            'reason':reason,
            'days':days,
            'type':type
        }
        $.ajax({
            url:"/closure/getAllUnseal",
            data:param,
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    }

    function demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"委托书",
            data:data,
            toolbar:'#button_ids',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,30],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'checkbox'},
                {title: '序号',align:'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"userCode",title:"封停用户编号",align:'center'},
                {field:"account",title:"封停账号",align:'center'},
                {field:"endDate",title:"解封时间",align:'center'},
                {field:"reason",title:"封停原因",align:'center'},
                {field:"days",title:"封停天数",align:'center',templet:function(data) {
                        if(data.days == 0){
                            return "已解封";
                        }else{
                            return data.days+"天";
                        }
                    }},
                {field:"type",title:"用户",align:'center',templet:function(data) {
                        if(data.type==2){
                            return "前端用户";
                        }else{
                            return "后端用户";
                        }
                    }},
                {field:'',title:"操作",align:'center',toolbar:'#button_caozuo'}
            ]]
        })
    }

    //删除解封日志
    table.on('tool(demoTable)',function (obj) {
        var event = obj.event;
        if (event == "deleteTable") {
            layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                $.ajax({
                    url:"/closure/delUnseal",
                    data:{'id':obj.data.id},
                    type:'post',
                    dataType:'json',
                    success:function (data) {
                        layer.msg("已删除！！！");
                        getTable("","","","");
                    }
                })
                layer.close(index);
            });
        }
    })

})